<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>浙江孵化器在线后台管理系统---系统管理---邮件管理---发送邮件</title>
    <link href="<spring:url value="/static/style/index.css" htmlEscape="true" />" rel="stylesheet" type="text/css">
    <link href="<spring:url value="/static/resources/css/lTREE.checkbox.css" htmlEscape="true" />" rel="stylesheet" type="text/css">
    <link href="<spring:url value="/static/resources/css/calendar-blue.css" htmlEscape="true" />" rel="stylesheet" type="text/css">
    <link href="<spring:url value="/static/js/tree/xtree.css" htmlEscape="true" />" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="<spring:url value="/static/js/tree/tree.js" htmlEscape="true" />"></script>
    <script type="text/javascript" src="<spring:url value="/static/js/Calendarguo.js" htmlEscape="true" />"></script>
</head>
<body>
<div class="list_right_title">
    <span><img src="<spring:url value="/static/images/email_icon.jpg" htmlEscape="true" />" alt="邮件管理"></span>系统管理>>邮件管理>发送邮件
</div>
<div class="step_mail_title">
    <ul>
        <li class="step_mail_title_select">发送邮件</li>
        <li><a href="listSuccessEmails">已发邮件</a></li>
    </ul>
</div>
<form:form modelAttribute="email" method="post" action="saveManageSendEmail" name="emailForm">
    <input type="hidden" name="contactMixStr" id="contactMixStr"/>
    <div class="step_btn">
        <span><input type="submit" value="　发送　"></span>
    </div>
    <div class="step_mail">
        <div class="step_mail_form">
            <div class="step_mail_left">
                <table summary="发送邮件表单" cellspacing="0" cellpadding="0" class="step_form">
                    <tr>
                        <th width="15%" align="right"><label for="title">收件人：</label></th>
                        <td width="85%">
                            <div style="border: 1px solid rgb(173, 173, 174); background-color:white; width: 97%;">&nbsp;<span id="showToMail" >&nbsp;</span></div><span id="no_user"></span>
                        </td>
                    </tr>
                    <tr>
                        <th width="15%" align="right"><label for="title">外部收件人：</label></th>
                        <td width="85%"><input type="text" name="outAcceptorName" id="outAcceptorNameID" class="step_form_input"/></td>
                    </tr>
                    <tr>
                        <th width="15%" align="right"><label for="title">主题：</label></th>
                        <td width="85%"><form:input path="topic" class="step_form_input"/></td>
                    </tr>
                    <tr>
                        <th align="right"><label for="template">模板：</label></th>
                        <td>
                            <select name="emailTemplate" onchange="onselectChange()" id="emailTemplate">
                                <c:forEach var="emailTemplate" items="${emailTemplateList}">
                                    <option value="<c:out value="${emailTemplate.content}"  escapeXml="true"/>">${emailTemplate.name}</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" align="right"><label for="content">正文：</label></th>
                        <td>
                            <FCK:editor instanceName="EditorDefault" inputName="content" value="${email.content}" height="400">
                                    </FCK:editor>
                        </td>
                    </tr>
                    <tr>
                        <th width="15%" align="right"><label for="title">发送人：</label></th>
                        <td width="85%">
                            <form:select path="senderName" items="${emailSenderMap}" onchange="changeEmailSenderPassword(this)"/>
                        </td>
                    </tr>
                    <tr>
                        <th align="right">定时发送：</th>
                        <td align="left">
                            日期：<input name="scheduleSendDate" type="text" class="fhq_add_select" id="myCalendar" readonly="true"/>
                            <img src="<spring:url value="/static/images/calendar.gif" htmlEscape="true" />"
                                 onclick="return showCalendar('myCalendar','y-mm-dd');"/>
                            时间：
                            <select name="scheduleSendHour">
                                <c:forEach begin="00" end="23" var="n">
                                    <option value="${n}">${n}</option>
                                </c:forEach>
                            </select>:时
                            <select name="scheduleSendMinute">
                                <c:forEach begin="00" end="59" var="n">
                                    <option value="${n}">${n}</option>
                                </c:forEach>
                            </select>:分<br/>
                            <form:checkbox path="scheduleSend"/><label for="定时发送">定时发送</label>
                            <form:checkbox path="saveHistory"/><label for="保存到已发送">保存到"已发送"</label>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="org_tree">
                <div class="org_tree_title">选择收件人</div>
                <div class="org_tree_list">
                    <div class="lTREEMenu lTREENormal" id="process_tree">
                        <%--<c:forEach var="contactGroup" items="${contactGroupList}">
                            <dl>
                                <dd><input type="checkbox" value=""/>${contactGroup.name}
                                    <c:forEach var="contactMember" items="${contactGroup.contactMembers}">
                                        <dl>
                                            <dt>
                                                <input name="contactMemberID" type="checkbox"
                                                       value="${contactMember.id}"/>${contactMember.name}</dt>
                                        </dl>
                                    </c:forEach>
                                </dd>
                            </dl>
                        </c:forEach>--%>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="step_btn">
        <span><input type="button" onclick="save()" value="　发送　"></span>
  <%--      <span><input type="submit" value="　发送　"></span>--%>
    </div>
</form:form>
</body>
<script type="text/javascript">
    function onselectChange() {
        FCKeditorAPI.GetInstance("EditorDefault").EditorDocument.body.innerHTML = document.getElementById("emailTemplate").value;
    }
</script>
<script type="text/javascript">
    var treeDate=new Array();
     var row=0;
     <c:forEach var="treeJsModel" items="${treeJsModelList}" varStatus="status">
        treeDate[row]=(new Array("${treeJsModel.parentNodeID}","${treeJsModel.currentNodeID}","${treeJsModel.currentNodeName}",0,${treeJsModel.haveChild},${treeJsModel.checked}));
          row++;
    </c:forEach>
</script>
 <script type="text/javascript">
    var tree = null;
    var checkedIds="";
    function createMenuTree(){
        var rootTreeNode = null;
        var treeArray=new Array();
        var sAction="";
        var menuOrExp;
        tree = new WebFXTree("tree"," ");
        for(var i=0;i<treeDate.length;i++){
            if(treeDate[i][3]==0){
                if(treeDate[i][4])rootTreeNode  = new WebFXTreeItem(treeDate[i][0]+","+treeDate[i][1],treeDate[i][2],"","","","","",treeDate[i][5],"2");
                else rootTreeNode  = new WebFXTreeItem(treeDate[i][0]+","+treeDate[i][1],treeDate[i][2],"","","","","",treeDate[i][5],"2");
            }else{
                rootTreeNode  = new WebFXTreeItem(treeDate[i][0]+","+treeDate[i][1],treeDate[i][2],"","","","","",treeDate[i][5],"2");
            }

            if(treeDate[i][0]=="0"){
                tree.add(rootTreeNode);
            }else{
                for(var j=0;j<treeArray.length;j++){
                    if(treeArray[j][1]==treeDate[i][0]){
                        treeArray[j][0].add(rootTreeNode);
                        break;
                    }
                }
            }
            treeArray[i]=(new Array(rootTreeNode,treeDate[i][1]));
        }
        document.getElementById("process_tree").innerHTML = tree;
   }

    function getChildValue(obj){
        addValueToArray(obj);
        for(var i=0;i<obj.childNodes.length;i++){
            getChildValue(obj.childNodes[i]);
        }
    }

    function addValueToArray(obj){
        if(obj.haveCheckBox&&document.getElementById(obj.id+"-checkbox")&&document.getElementById(obj.id+"-checkbox").checked){
         	checkedIds = checkedIds+obj.bizId+"#";
        }
    }

    function getCheckIDs(){
        for(var i=0;i<tree.childNodes.length;i++){
            getChildValue(tree.childNodes[i]);
        }
    }

    function save(){
	    checkedIds="";
    	if(tree.haveCheckBox&&document.getElementById(tree.id+"-checkbox")&&document.getElementById(tree.id+"-checkbox").checked){
       	checkedIds = checkedIds+tree.bizId+";";
        }else{
    		getCheckIDs();
    	}
      //  alert(checkedIds);
        if(checkedIds.indexOf("member_")==-1 && checkedIds.indexOf("enterprise_")==-1 )
        {
            alert("请选择接收人！");
            return;
        }
        document.getElementById("contactMixStr").value = checkedIds;
     //   alert(checkedIds);
        document.getElementById("email").submit();
    }
</script>
<script>
    createMenuTree();
</script>
</html>